<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class Refuse
{
    protected $id;

    public function __construct($oid = '', $name)
    {
        $this->oid = $oid;
        $this->name = $name;
    }

    protected function script()
    {
        return <<<SCRIPT

layui.use('layer', function(){
        var layer = layui.layer;
        $('.refuser').click(function () {
           var that = this;
           var oid = $(that).attr('data-oid');
           var name = $(that).attr('data-name');
           var index = layer.open({
               type: 1,
               content: '<\/br><\span style="color:red;padding-left:20px;">'+name+'<\/span> 拒绝<\/br><\input name="reason" style="width: 200px;margin-left: 20px;margin-top: 10px;" placeholder="请输入拒绝理由">',
               area:['300px', '200px'],
               btn:['确定', '取消'],
               yes: function(index, layero){
                   var refuseReason = $('input[name=reason]').val();
                   $.ajax({
                     url: '/admin/common/order/rejudge?type=deny&oid='+oid+'&refuseReason='+refuseReason,
                     type: 'get',
                     success:function(res){
                        if(res.code == 0){
                            layer.msg('修改成功');
                            $(that).text('审核拒绝').addClass('layui-bg-red');
                            layer.close(index);
                        }else{
                            layer.msg('修改失败');
                        }
                     }
                   });
               },
           });
       });
    });
SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "&nbsp;<a class='refuser layui-btn layui-btn-danger layui-btn-xs' data-name='{$this->name}' data-oid='{$this->oid}'>拒绝</a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}